//
//  PPBottomBarView.m
//  PPCheckTool
//
//  Created by BenJim on 2019/4/5.
//

#import "PPBottomBarView.h"


@interface PPBottomBarView ()

// 回到顶端
@property (nonatomic, strong) UIButton * homeBtn;

// 重新load
@property (nonatomic, strong) UIButton * refreshBtn;

//下一个
@property (nonatomic, strong) UIButton * nextBtn;

//上一个
@property (nonatomic, strong) UIButton * topBtn;

@end


@implementation PPBottomBarView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupViews];
    }
    return self;
}

- (void) setupViews{
    [self addSubview:self.homeBtn];
    
    [self addSubview:self.refreshBtn];
    
    [self addSubview:self.nextBtn];
    
    [self addSubview:self.topBtn];
    
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[_homeBtn(_refreshBtn)]-0-[_refreshBtn]-0-[_nextBtn(_refreshBtn)]-0-[_topBtn(_refreshBtn)]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_homeBtn,_refreshBtn,_nextBtn,_topBtn)]];
    
    
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_homeBtn]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_homeBtn)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_refreshBtn]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_refreshBtn)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_nextBtn]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_nextBtn)]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_topBtn]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_topBtn)]];
    
    [self.homeBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.refreshBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.nextBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.topBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    self.homeBtn.tag = 1000;
    
    self.refreshBtn.tag = 1001;
    self.nextBtn.tag = 1002;
    self.topBtn.tag = 1003;

}

- (void)click:(id)sender{
    
    UIButton * btn = (UIButton *)sender;
    
    NSInteger type = btn.tag - 1000;
    
    if (self.deleagte && [self.deleagte respondsToSelector:@selector(clickBottomWith:)]) {
        [self.deleagte clickBottomWith:type];
    }
}


- (UIButton *)homeBtn {
    if (!_homeBtn) {
        _homeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_homeBtn setTitle:@"首页" forState:UIControlStateNormal];
        [_homeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _homeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _homeBtn.translatesAutoresizingMaskIntoConstraints = NO;
    }
    return _homeBtn;
}


- (UIButton *)refreshBtn {
    if (!_refreshBtn) {
        _refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_refreshBtn setTitle:@"重试" forState:UIControlStateNormal];
        [_refreshBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _refreshBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _refreshBtn.translatesAutoresizingMaskIntoConstraints = NO;

    }
    return _refreshBtn;
}

- (UIButton *)topBtn{
    if (!_topBtn) {
        _topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_topBtn setTitle:@"后退" forState:UIControlStateNormal];
        [_topBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _topBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _topBtn.translatesAutoresizingMaskIntoConstraints = NO;

    }
    return _topBtn;
}

- (UIButton *)nextBtn{
    if (!_nextBtn) {
        _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nextBtn setTitle:@"前进" forState:UIControlStateNormal];
        [_nextBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _nextBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _nextBtn.translatesAutoresizingMaskIntoConstraints = NO;

    }
    return _nextBtn;
}

@end
